/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = t__sip_add_error_nums.c                           */
/*  NOTE      =                                                    */
/*  DATE      = 2016/02/16 by songbb                               */
/*******************************************************************/

#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"

#include "../../../src/module/sip/config.h"
#include "../test_sip_comm.h"
#include <sip/sip_core.h>
#include <sip/sip_header.h>
#include <sip/sip_comm.h>
#include <sip/sip_packet.h>
#include <frct_comm.h>

extern void __sip_add_error_nums(L7session_sip *p_st_sess);

static int __suite_init(void)
{
    return 0;
}

static int __suite_cleanup(void)
{
    return 0;
}

static void __case1(void)
{
    Conntrack *p_st_conn = NULL;
    CU_ASSERT_EQUAL(test_sip_create_ct(&p_st_conn, TEST_SIP_SRC_IP, TEST_SIP_DST_IP, TEST_SIP_SRC_PORT, TEST_SIP_DST_PORT), FR_SUCC);

    L7_session *p_st_session = frct_get_session(p_st_conn);

    L7session_sip_private *p_st_session_private = (L7session_sip_private *) frct_get_session_private(p_st_session);
    L7session_sip *p_st_sess = p_st_session_private->p_st_sess;

    __sip_add_error_nums(p_st_sess);
    __sip_add_error_nums(p_st_sess);
    __sip_add_error_nums(p_st_sess);

    CU_ASSERT_EQUAL(p_st_sess->ull_error_nums, 3L);

    test_sip_destroy_ct(&p_st_conn);
    CU_ASSERT_PTR_NULL(p_st_conn);
}

int add_suite__sip_add_error_nums(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" __sip_add_error_nums()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    if (CU_add_test(pSuite, "case1", __case1) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
